clear;clc;
%%
lp=arrayfun(@(order) EquipmentControl.FeedBackOptimization.LTIUnit.LowPassFilter(order, 10), 1:8);

%%
tune=EquipmentControl.FeedBackOptimization.PIDOptimizer(lp(1));
figure; a1=subplot(2, 1, 1); a2=subplot(2, 1, 2);
tune.PIChart('delay', 0.0, 'axes', a1);
tune.PIChart('delay', 0.01, 'axes', a2);
%%
% c=tune.optimPID('type','PI');
[cPID1, val, t]=tune.optimPID('type','PID', 'weight', 1, 'costfun', 'IAE');
[cPID0, val, t]=tune.optimPID('type','PID', 'weight', 0, 'costfun', 'IAE');

figure;
[y1, t1]=step(feedback(g.tfFunction*cPID1, 1), t);
[y2, t2]=step(feedback(g.tfFunction*cPID0, 1), t);

[y3, t3]=step(feedback(g.tfFunction, cPID1), t);
[y4, t4]=step(feedback(g.tfFunction, cPID0), t);

subplot(2, 1, 1)
plot(t1, y1, 'r.-', t2, y2, 'b.-');
subplot(2, 1, 2)
plot(t3, y3, 'r.-', t4, y4, 'b.-');